package com.codefish.controller;

import com.codefish.entity.ProvinceCityCounty;
import com.codefish.service.ProvinceCityCountyService;
import com.codefish.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Classname ProvinceCityCountyController
 * @Description 省市区
 * @Date 2021/4/30 22:19
 * @Created 学兔斯基眯眼看世界
 */
@RestController
@RequestMapping("/provinceCityCounty")
public class ProvinceCityCountyController {

    @Autowired
    private ProvinceCityCountyService provinceCityCountyService;

    /**
     * 省市区树形结构查询
     *
     * @return
     */
    @GetMapping("/queryCity")
    public List<Map<String, Object>> queryCity() {
        return provinceCityCountyService.queryProvinceCityCounty();
    }

    /**
     * 查询全部的省
     *
     * @return
     */
    @GetMapping("/queryProvince")
    public List<ProvinceCityCounty> queryProvince() {
        return provinceCityCountyService.queryProvince();
    }

    /**
     * 根据id查询对应下级
     * 根据省的id查询对应下的市
     * 根据市id查询其下的县(区)
     *
     * @param id
     * @return
     */
    @GetMapping("/queryCityByProvinceId")
    public List<ProvinceCityCounty> queryCityByProvinceId(@RequestParam Long id) {
        return provinceCityCountyService.queryCityByProvinceId(id);
    }
}
